package spotify;

import database.DatabaseConnector;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Serhat
 * Date: 1-6-13
 * Time: 14:48
 */
public class TrackSearcher {

    private static Connection connection;

    public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException {
        connection = DatabaseConnector.getInstance().getConnection();
        SpotifyGateway sg = new SpotifyGateway();
        XMLParser xmlp = XMLParser.getInstance();
        String result = sg.doSearch(getInput());
        xmlp.parse(result);
        System.out.println("done");
    }

    public static String getInput() {
        Scanner sc = new Scanner(System.in);
        System.out.println("Voer een zoekterm in!");
        return saveInput(sc.nextLine());
    }

    public static String saveInput(String input) {
        String inputSpaces = "";
        for (char c : input.toCharArray()) {
            if (c == " ".charAt(0)) inputSpaces += "%20";
            else inputSpaces += c;
        }
        return inputSpaces;
    }
}
